﻿using System.ComponentModel;
using System.Reflection;

namespace System;

public static class EnumExtension
{
    public static string GetDescription(this Enum enumValue)
    {
        FieldInfo field = enumValue.GetType().GetField(enumValue.ToString());
        if (field == null)
            return "-";

        DescriptionAttribute attribute = Attribute.GetCustomAttribute(field, typeof(DescriptionAttribute)) as DescriptionAttribute;
        return attribute == null ? enumValue.ToString() : attribute.Description;
    }
}
